﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="SpellCheckeCS.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SpellCheckeCS"
    xmlns:common="using:SpellCheckeCS.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">Spell Checker WinRT Component Wrapper</x:String>
        <DataTemplate x:Key="listViewDataTemplate">
            <Grid Width="120" Height="120">
                <Rectangle Fill="Green"></Rectangle>
                <TextBlock Text="{Binding LangTag}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"></TextBlock>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid  Grid.Column="0" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Border Grid.Row="0" BorderBrush="Cyan" BorderThickness="3"/>
                <StackPanel Orientation="Vertical">
                    <TextBlock Margin="0,12,0,12" FontSize="15" HorizontalAlignment="Center" FontWeight="ExtraBold">Supported Languages</TextBlock>
                    <StackPanel Orientation="Horizontal" Margin="1">
                        <Button Grid.Row="0" Margin="6" VerticalAlignment="Top" Style="{StaticResource PreviewButtonStyle}" Click="ButtonClick_SupportedLanguages"></Button>
                        <TextBlock Text="{Binding SupportedLangCount}" FontSize="30" FontWeight="Bold" FontFamily="Global User Interface" Foreground="Cyan" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </StackPanel>
                </StackPanel>
                <Border Grid.Row="1" BorderBrush="Cyan" BorderThickness="3"/>
                <StackPanel Grid.Row="1" Grid.Column="0" Margin="3" >
                    <TextBlock Margin="0,12,0,12" FontSize="15" HorizontalAlignment="Center" FontWeight="ExtraBold">Check Spellings</TextBlock>
                    <TextBox Name="textWord" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Width="200" Text="Word Here" GotFocus="textWord_GotFocus"></TextBox>
                    <TextBlock Name="languageTag" Text="Language [ en-US ]" />
                    <Button Grid.Column="1" Style="{StaticResource CheckButtonStyle}" VerticalAlignment="Top" HorizontalAlignment="Center" Click="ButtonClick_CheckSpelling" AutomationProperties.Name="Check Spellings" />
                    <StackPanel Margin="12" Orientation="Horizontal">
                        <TextBlock>Spelling Correct</TextBlock>
                        <Grid>
                            <Rectangle Margin="12,0,0,0" Width="10" Height="10" Fill="Red" Visibility="{Binding SpellingInCorrect}"></Rectangle>
                            <Rectangle Margin="12,0,0,0" Width="10" Height="10" Fill="Green" Visibility="{Binding SpellingCorrect}"></Rectangle>
                            <Rectangle Margin="12,0,0,0" Width="10" Height="10" Fill="White" Visibility="{Binding SpellingResultsAvailable}"></Rectangle>
                        </Grid>
                    </StackPanel>
                    <ListView Margin="12,3,12,0" Name="listViewSuggestions" Header="Suggestions(if any)" Height="200" ItemsSource="{Binding Suggestions}"></ListView>
                    <StackPanel Margin="12" Orientation="Vertical">
                        <TextBlock>Replacement(if any)</TextBlock>
                        <TextBlock Text="{Binding ReplacementIfAny}"></TextBlock>
                    </StackPanel>
                </StackPanel>
        </Grid>
            <Grid Grid.Column="1">
                <Border BorderBrush="#FF5B2222" BorderThickness="3"></Border>
                <GridView Name="listViewLanguages" 
                          HorizontalAlignment="Stretch" 
                          Padding="3" 
                          ItemsSource="{Binding LanguageTags}" 
                          ItemTemplate="{StaticResource listViewDataTemplate}" />
            </Grid>
        </Grid>
        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
